Conditions | 1 |
Paths | 1 |
Total Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import callAPIMethod from './callAPIMethod'; |
||
5 | const createAPI = (resources = {}, middleware = [], APIPrefix = '', fetchOptions = {}) => |
||
6 | |||
7 | Object.keys(resources).reduce( (api, resourceId) => { |
||
8 | api[resourceId] = Object.keys(resources[resourceId].methods).reduce( (resource, method) => { |
||
9 | resource[method] = (params, methodOptions) => { |
||
10 | const apiParams = resources[resourceId].methods[method](params); |
||
11 | const bindedCallAPIMethod = callAPIMethod.bind(null, APIPrefix, fetchOptions, resources[resourceId].prefix); |
||
12 | return applyMiddleware(bindedCallAPIMethod, middleware, methodOptions, apiParams, resourceId, method); |
||
13 | }; |
||
14 | return resource; |
||
15 | }, {}); |
||
16 | return api; |
||
17 | }, {}); |
||
18 | |||
20 | export default createAPI; |